namespace SIMCIntegratedReports
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using Telerik.Reporting;
    using Telerik.Reporting.Drawing;
    using SIMCFachadaNegocio;
    using SIMCObjetoNegocio;

    /// <summary>
    /// Summary description for rptAportyRet.
    /// </summary>
    public partial class rptAportyRet : Telerik.Reporting.Report
    {
        public rptAportyRet()
        {
            /// <summary>
            /// Required for telerik Reporting designer support
            /// </summary>
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        private void rptAportyRet_NeedDataSource(object sender, EventArgs e)
        {

            FachadaPortafolio fachada = new FachadaPortafolio();

            Portafolio port = fachada.BuscarPortafolio(int.Parse(ReportParameters["Portafolio"].Value.ToString()), DateTime.Parse(ReportParameters["FechaIni"].Value.ToString()));

            txtCliente.Value = port.NombreTitular;

            txtDivisa.Value = port.DivisaBase;

            txtPortafolio.Value = port.Id.ToString();
            
            dataAportesRetirosTableAdapters.pa_AR_portafolio_periodoTableAdapter adapAR = new dataAportesRetirosTableAdapters.pa_AR_portafolio_periodoTableAdapter();
            
            dataAportesRetiros.pa_AR_portafolio_periodoDataTable datosCrudos = new dataAportesRetiros.pa_AR_portafolio_periodoDataTable();
            adapAR.Fill(datosCrudos, int.Parse(ReportParameters["Portafolio"].Value.ToString()), DateTime.Parse(ReportParameters["FechaIni"].Value.ToString()),
                DateTime.Parse(ReportParameters["FechaFin"].Value.ToString()), 1, 1);
            dataAportesRetiros.dtAportYRetDataTable tablaFinal = new dataAportesRetiros.dtAportYRetDataTable();
            tablaFinal.Merge(datosCrudos, true, System.Data.MissingSchemaAction.Ignore);

            System.Data.DataColumn dc1 = new System.Data.DataColumn("Saldo", typeof(double));
            System.Data.DataColumn dc2 = new System.Data.DataColumn("SaldoIni", typeof(double));
            tablaFinal.Columns.Add(dc1);
            tablaFinal.Columns.Add(dc2);
            double SaldoPrevio = 0;//double.Parse(dtSaldoIni[0]["NETO_ini"].ToString().Trim());
            foreach (System.Data.DataRow b in tablaFinal.Rows)
            {
                //b["Cliente"] = cliente[0][0].ToString().Trim();
                b["SaldoIni"] = 0;
                b["Saldo"] = 0;
                if (b["IE"].ToString().Trim().Equals("E"))
                    b["Saldo"] = SaldoPrevio - double.Parse(b["MontoBase"].ToString().Trim());
                else
                    b["Saldo"] = SaldoPrevio + double.Parse(b["MontoBase"].ToString().Trim());
                SaldoPrevio = double.Parse(b["Saldo"].ToString().Trim());
            }
            tablaFinal.AcceptChanges();
            this.DataSource = tablaFinal;

           
            
        }


    }
}